package com.mtoanmy.loading;

import com.mtoanmy.tmlibrary.R;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Loading extends LinearLayout {

	AnimationDrawable lightsAnimation;
	ImageView image;

	public Loading(Context context, AttributeSet attrs) {
		super(context, attrs);

		String infService = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li;

		li = (LayoutInflater) getContext().getSystemService(infService);
		li.inflate(R.layout.loading, this, true);

		image = (ImageView) findViewById(R.id.imageView1);
		lightsAnimation = (AnimationDrawable) image.getDrawable();

		this.setVisibility(View.GONE);
	}

	public void stop() {
		lightsAnimation.stop();
		this.setVisibility(View.GONE);
	}

	public void start() {
		this.setVisibility(View.VISIBLE);
		image.post(new Runnable() {

			public void run() {
				lightsAnimation.start();
			}
		});
	}
}
